package com.husd.framework.awarlmart;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * @author shengdonghu@126.com
 * @date 2023/10/19 10:40
 */
@Data
public class WarlmartApiExcelRow {

    @ColumnWidth(15)
    @ExcelProperty(value = "字段", index = 0)
    private String name;
    // type如果是Object 就需要递归处理 生成多个
    @ColumnWidth(15)
    @ExcelProperty(value = "字段类型", index = 1)
    private String type;
    @ColumnWidth(15)
    @ExcelProperty(value = "title", index = 2)
    private String title;
    // 如果是字符串 就是字符串的长度
    // 如果是数字 就是数字的范围
    @ColumnWidth(15)
    @ExcelProperty(value = "字符串的最小长度或数字的最小值", index = 3)
    private String min;
    @ColumnWidth(15)
    @ExcelProperty(value = "字符串的最大长度或数字的最大值", index = 4)
    private String max;
    /**
     * 关于数组类型的一个描述
     */
    @ColumnWidth(15)
    @ExcelProperty(value = "数据的元素类型描述", index = 5)
    private String arrayItemsDesc;
    @ColumnWidth(15)
    @ExcelProperty(value = "description", index = 6)
    private String description;
    @ColumnWidth(15)
    @ExcelProperty(value = "examples", index = 7)
    private String examples;
    @ColumnWidth(15)
    @ExcelProperty(value = "comments", index = 8)
    private String comments;
    @ColumnWidth(15)
    @ExcelProperty(value = "必填/可选", index = 9)
    private String required;
    /**
     * 额外属性校验
     * 为 false 时不允许拥有除了 properties 和 patternProperties
     * 匹配到的属性外的属性，如果为 Scheme 实例，
     * 则没有匹配到的属性要符合该 Scheme
     */
    @ColumnWidth(15)
    @ExcelProperty(value = "额外属性校验", index = 10)
    private String additionalProperties;
    @ColumnWidth(15)
    @ExcelProperty(value = "备注", index = 11)
    private String remark;

    public void setName(String name) {
        this.name = maxLen(name, 32700);
    }

    public void setType(String type) {
        this.type = type;
    }

    public void setTitle(String title) {
        this.title = maxLen(title, 32700);
    }

    public void setMin(String min) {
        this.min = min;
    }

    public void setMax(String max) {
        this.max = max;
    }

    public void setArrayItemsDesc(String arrayItemsDesc) {
        this.arrayItemsDesc =  maxLen(arrayItemsDesc, 32700);
    }

    public void setDescription(String description) {
        this.description = maxLen(description, 32700);
    }

    public void setExamples(String examples) {
        this.examples = maxLen(examples, 32700);
    }

    public void setComments(String comments) {
        this.comments = maxLen(comments, 32700);
    }

    public void setRequired(String required) {
        this.required = required;
    }

    public void setAdditionalProperties(String additionalProperties) {
        this.additionalProperties = additionalProperties;
    }

    public void setRemark(String remark) {
        this.remark = maxLen(remark, 32700);
    }

    private String maxLen(String str, int len) {

        if(StringUtils.isNotBlank(str) && str.length() >= len) {
            return str.substring(0,len);
        }
        return str;
    }
}
